package com.ces.knacky.controller.tools;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ces.knacky.framework.controller.BaseController;
import com.ces.knacky.framework.model.IEntity;
import com.ces.knacky.model.Flag;
import com.ces.knacky.model.Item;
import com.ces.knacky.model.ItemWorkflowStatus;
import com.ces.knacky.model.UserTable;
@Controller
public class SaveItemController extends BaseController {
	
	private String name;
	
	private String description;
	
	private Float expectedPrice;
	
	@RequestMapping ("/saveItem.htm")	
	public String execute(){
		System.out.println("Inside Save Item");
		Item item = new Item();
		item.setDescription(description);
		item.setTitle(name);
		item.setExpectedPrice(expectedPrice);
		item.setCreateTime(new Date());
		item.setUpdateTime(new Date());
		//Dummy Item Code
		//item.setCode(name + "Code");
		item.setCode("code");
		IEntity entity = commonService.findFirstByDescription(UserTable.class, "admin");
		item.setUser((UserTable)entity);
		entity = commonService.findFirstByDescription(Flag.class, "ACTIVE");
		item.setFlag((Flag)entity);
		entity = commonService.findFirstByDescription(ItemWorkflowStatus.class, "Draft");
		item.setItemWorkflowStatus((ItemWorkflowStatus)entity);
		commonService.add(item);
		
		return "saveItem";
	}
	
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	@ModelAttribute("name")	
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the description
	 */	
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	@ModelAttribute("description")
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the expectedPrice
	 */
	public Float getExpectedPrice() {
		return expectedPrice;
	}

	/**
	 * @param expectedPrice the expectedPrice to set
	 */
	@ModelAttribute("expectedPrice")
	public void setExpectedPrice(Float expectedPrice) {
		this.expectedPrice = expectedPrice;
	}



}
